home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
src
/
fig04_14.jar
/
Ch04
/
Fig04_14
/
Fig04_14.cpp
Wrap
C/C++ Source or Header
|
1997-10-13
|
1KB
|
53 lines
// Fig. 4.14: fig04_14.cpp
// Passing arrays and individual array elements to functions
#include <iostream.h>
#include <iomanip.h>
void modifyArray( int [], int ); // appears strange
void modifyElement( int );
int main()
{
const int arraySize = 5;
int i, a[ arraySize ] = { 0, 1, 2, 3, 4 };
cout << "Effects of passing entire array call-by-reference:"
<< "\n\nThe values of the original array are:\n";
for ( i = 0; i < arraySize; i++ )
cout << setw( 3 ) << a[ i ];
cout << endl;
// array a passed call-by-reference
modifyArray( a, arraySize );
cout << "The values of the modified array are:\n";
for ( i = 0; i < arraySize; i++ )
cout << setw( 3 ) << a[ i ];
cout << "\n\n\n"
<< "Effects of passing array element call-by-value:"
<< "\n\nThe value of a[3] is " << a[ 3 ] << '\n';
modifyElement( a[ 3 ] );
cout << "The value of a[3] is " << a[ 3 ] << endl;
return 0;
}
void modifyArray( int b[], int sizeOfArray )
{
for ( int j = 0; j < sizeOfArray; j++ )
b[ j ] *= 2;
}
void modifyElement( int e )
{
cout << "Value in modifyElement is "
<< ( e *= 2 ) << endl;
}